package controller

import (
	"hft/Database/admin"
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"strconv"

	"github.com/gin-gonic/gin"
)

type AboutSmallCategory struct{}

func (*AboutSmallCategory) Create(c *gin.Context) {

	var data *admin.SmallCategory

	c.ShouldBindJSON(&data)

	err := services.AboutSmallCategoryService.Create(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*AboutSmallCategory) Edit(c *gin.Context) {

	var data *admin.SmallCategory

	c.ShouldBindJSON(&data)

	err := services.AboutSmallCategoryService.Edit(data)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*AboutSmallCategory) List(c *gin.Context) {

	id, _ := strconv.Atoi(c.DefaultQuery("id", "0"))

	data, err := services.AboutSmallCategoryService.List(id)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(data, c)

}

func (*AboutSmallCategory) Delete(c *gin.Context) {

	var ids *request.IDS

	c.ShouldBindJSON(&ids)

	err := services.AboutSmallCategoryService.Delete(ids.IDS)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

var AboutSmallCategoryController = new(AboutSmallCategory)
